package com.qyer.lxp.lxdao.order.impl;

import com.qyer.lxp.common.framework.contants.QyerMethodNameContants;
import com.qyer.lxp.common.framework.convert.TransformSession;
import com.qyer.lxp.common.framework.core.BaseSpringService;
import com.qyer.lxp.lxdao.order.IBookProvideDao;
import com.qyer.lxp.model.availability.normal.Available;
import com.qyer.lxp.model.availability.parameter.AvailabilityRequest;
import com.qyer.lxp.model.book.normal.Book;
import com.qyer.lxp.model.book.parameter.BookRequest;
import com.qyer.lxp.model.booklimits.normal.BookLimit;
import com.qyer.lxp.model.booklimits.normal.BookLimits;
import com.qyer.lxp.model.booklimits.parameter.BookLimitRequest;
import com.qyer.lxp.model.orderstatus.normal.OrderStatus;
import com.qyer.lxp.model.orderstatus.normal.OrderStatuses;
import com.qyer.lxp.model.orderstatus.parameter.OrderStatusRequest;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 预订供应接口类
 * Created by jiangping on 16/5/13.
 */

@Component
public class BookProvideDaoImpl extends BaseSpringService implements IBookProvideDao{
    /**
     * 验价接口
     * 功能说明：传入购买的销售项目code，以及购买的规格或附加选项的code和数量，
     * 获取相应的可售信息和最新的准确价格信息
     *
     * @param availabilityRequest 需要验价参数的封装对象
     * @return 返回验价结果
     * @throws Exception
     */
    public Available getAvailablity(AvailabilityRequest availabilityRequest) throws Exception {
        if(null == availabilityRequest){
            return null;
        }
        Available available= (Available) TransformSession.selectExtraOne(QyerMethodNameContants.LX_METHOD_NAME_GETAVAILABLITY,availabilityRequest,QyerMethodNameContants.LX_CLASS_NAME_AVAILABLE);
        return available;
    }

    /**
     * 预定限制接口
     * @param bookLimitRequest
     * @return
     * @throws Exception
     */
    @Override
    public List<BookLimit> getBookLimits(BookLimitRequest bookLimitRequest) throws Exception {
        if(null == bookLimitRequest){
            return null;
        }
        List<BookLimit> bookLimitList = null;
        BookLimits bookLimits = (BookLimits) TransformSession.selectOne(QyerMethodNameContants.LX_METHOD_NAME_GETBOOKLIMITS, bookLimitRequest, QyerMethodNameContants.LX_CLASS_NAME_BOOKLIMITS);
        if(null != bookLimits){
            bookLimitList = bookLimits.getBookLimits();
        }
        return bookLimitList;
    }

    /**
     * 获取订单状态
     * @param orderStatusRequest
     * @return
     * @throws Exception
     */
    public List<OrderStatus> getOrderStatus(OrderStatusRequest orderStatusRequest) throws Exception {
        List<OrderStatus> list=null;
        if(null == orderStatusRequest){
            return null;
        }
        OrderStatuses orderStatus= (OrderStatuses) TransformSession.selectOne(QyerMethodNameContants.LX_METHOD_NAME_GETORDERSTATUS,orderStatusRequest,QyerMethodNameContants.LX_CLASS_NAME_ORDERSTATUS);
        if(null!=orderStatus){
            list=orderStatus.getOrderStatuses();
        }
        return list;
    }

    /**
     * 调用力行预订接口,预订产品生成订单
     *
     * @param bookRequest 预订请求参数
     * @return 返回生成的订单信息
     * @throws Exception
     */
    @Override
    public Book getBook(BookRequest bookRequest) throws Exception {
        if(null == bookRequest){
            return null;
        }
        Book book = (Book) TransformSession.selectExtraOne(QyerMethodNameContants.LX_METHOD_NAME_BOOK,bookRequest,QyerMethodNameContants.LX_CLASS_NAME_BOOK);
        return book;
    }

}
